package com.kuizii.auth;

import com.kuizii.auth.util.AuthUtils;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.apache.shiro.authc.AuthenticationToken;

/**
 * @Author: nuanyang
 * @Date: 2019/7/24 0024 15:14
 */
@RequiredArgsConstructor
public class JWTToken implements AuthenticationToken {


    private final String token;

    public String getToken() {
        return this.token;
    }

    /**
     * 等同用户名
     *
     * @return
     */
    @Override
    public Object getPrincipal() {
        return this.token;
    }

    /**
     * @return 取token
     */
    @Override
    public Object getCredentials() {
        return this.token;
    }

    /**
     * @return 用户名
     */
    public String getUserName() {
        return AuthUtils.getUsername(this.token);
    }

    public String getUserId() {
        return AuthUtils.getUserId(this.token);
    }
}
